def is_prime(num):
    if num <= 1:
        return False
    if num <= 3:
        return True
    if num % 2 == 0 or num % 3 == 0:
        return False
    i = 5
    while i * i <= num:
        if num % i == 0 or num % (i + 2) == 0:
            return False
        i += 6
    return True

def is_reversible_prime(num):
    str_num = str(num)
    reversed_str_num = str_num[::-1]
    reversed_num = int(reversed_str_num)
    if str_num == reversed_str_num:
        return False
    return is_prime(num) and is_prime(reversed_num)

# 读取输入
start = int(input())
end = int(input())

# 找出并输出所有反素数
for num in range(start, end + 1):
    if is_reversible_prime(num):
        print(num)